
use tables/estimates_bs_ci, clear 

/*
weekly bounds
- population
- icli 
- non-icli, h-m
- non-icli, h-i
- clear, h-m
- clear, h-i 
*/

** set up for reshape 
rename lb_pop lb_pop0
rename ub_pop ub_pop0 
rename p025_pop lb_pop1
rename p975_pop ub_pop1

foreach t in non clear icli pool {
	foreach suff in i m {
		rename lb_`t'_`suff' lb_`t'_`suff'0
		rename ub_`t'_`suff' ub_`t'_`suff'0
		rename p025_`t'_`suff' lb_`t'_`suff'1
		rename p975_`t'_`suff' ub_`t'_`suff'1
	}
}

keep week lb_* ub_*
reshape long lb_pop ub_pop lb_non_i ub_non_i lb_non_m ub_non_m ///
	lb_icli_m lb_icli_i ub_icli_m ub_icli_i ///
	lb_clear_i lb_clear_m ub_clear_i ub_clear_m ///
	lb_pool_m ub_pool_m lb_pool_i ub_pool_i, i(week) j(ci)

foreach v of varlist lb_* {
	gen s = string(`v', "%5.4f") + ", "
	drop `v'
	rename s `v'
	replace `v' = "[" + `v' if ~ci
	replace `v' = "(" + `v' if  ci
}

foreach v of varlist ub_* {
	gen s = string(`v', "%4.3f")
	drop `v'
	rename s `v'
	replace `v' = `v' + "] &" if ~ci
	replace `v' = `v' + ") &" if  ci
}
gen weeks = string(week, "%td") 
replace weeks  = subinstr(weeks, "2020", "", .) + " & "
replace weeks =  " & " if ci
list weeks lb_pop ub_pop in 1/2
replace ub_clear_i = subinstr(ub_clear_i, "&", "\\" , .)
replace ub_pool_m = subinstr(ub_pool_m, "&", "\\" ,.)
# delimit ;
outsheet weeks lb_pop ub_pop lb_non_m ub_non_m lb_pool_m ub_pool_m 
	if month(week)==6 using tables/bounds_pool_h.tex, 
	replace noquote noname delimit(" ")
;
# delimit cr
